﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sustainalytics.DataLayer.Shared;
using Sustainalytics.Entities;

namespace Sustainalytics.ESGRatings.BusinessLogic.ESGOnlineReport
{
    public class OnlineReportGeneralBusinessLogicUnit<T> : IOnlineReportGeneralBusinessLogicUnit<T> where T : IEntity, ICompanyRelatedEntity
    {
        private  readonly IRepositoryCollection<T> _repository;
                
        public OnlineReportGeneralBusinessLogicUnit(IRepositoryCollection<T> repository)
        {
            _repository = repository;
        }

        public OnlineReportGeneralBusinessLogicUnit(string connectionString)
        {
            _repository = new RepositoryCollection<T>(connectionString);
        }

        public IList<T> GetByCompanyId(Guid companyId, IEnumerable<int> universeIds)
        {
            return _repository.ReadAllWhere(item => item.CompanyId==companyId);
        }

        public T GetSingleByCompanyId(Guid companyId, IEnumerable<int> universeIds)
        {
            return _repository.ReadAllWhere(item => item.CompanyId==companyId,0,1).FirstOrDefault();
        }

        public void Create(T obj)
        {
             _repository.Create(obj);
        }

        public bool CreateBatch(IEnumerable<T> obj)
        {
            return _repository.CreateBatch(obj);
        }

        public void CreateOrUpdateBatch(IEnumerable<T> obj)
        {
             _repository.CreateOrUpdateBatch(obj);
        }

    }
}
